package com.kedi.usercenter.applogin.controller;

import com.kedi.usercenter.enums.ResultEnum;
import com.kedi.usercenter.exception.CommonException;
import com.kedi.usercenter.service.ImportentnewsService;
import com.kedi.usercenter.utils.ResultVoUtil;
import com.kedi.usercenter.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
* @Description:    重要新闻中心控制层
* @Author:         ytw
* @CreateDate:     2019/7/12 14:35
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
@RestController
public class ImportentNewsController {
    private static Logger logger = LoggerFactory.getLogger(ImportentNewsController.class);

    @Autowired
    private ImportentnewsService importentnewsService;

    /**
    * 方法实现说明  获取所有重要信息
    * @author      ytw
    *@param
    * @return
    * @exception
    * @date        2019/7/12 14:35
    */
    @RequestMapping("/news/importentnews/list")
    public List<Map<String, Object>> findList(){
        return   importentnewsService.findList();
    }

    /**
    * 方法实现说明 根据用户id获取消息
    * @author      ytw
    *@param             id
    * @return       status 0 表示 未读    1表示 已读
    * @exception
    * @date        2019/7/12 14:38
    */
    @RequestMapping("/news/importentnews/listOne")
    public List<Map<String, Object>> findOneNews(@RequestParam("id") Integer id){
      return   importentnewsService.findOne(id);
    }

    /**
     * 方法实现说明  更改消息状态
     * @author      ytw
     *@param
     * @return
     * @exception
     * @date        2019/8/3 17:58
     */
    @RequestMapping("/updateImportentnewsStatus")
    public ResultVo updateImportentnewsStatus(Integer importentnewsid, Integer status){
        if(status==0){
            importentnewsService.updateImportentnewsStatus(importentnewsid);
            return ResultVoUtil.success();
        }else {
            throw new CommonException(ResultEnum.REQUEST_NULL);
        }

    }
}
